package testcase;

import java.io.File;
import java.lang.reflect.Constructor;
import java.util.ArrayList;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;

import dataobj.*;
import MainComponent.*;

public class TestTimeTableCreator extends TestCase{
	class testICSTrue extends ICSGenerator{
		public boolean createICSByCourses(ArrayList<CourseTO> to, String u, String loc){
			return true;
		}
	}
	
	class testICSFalse extends ICSGenerator{
		public boolean createICSByCourses(ArrayList<CourseTO> to, String u, String loc){
			return false;
		}
	}
	
	class testCourseOperateSize0 extends CourseOperate{
		public ArrayList<CourseTO> getCourses(File file){
			return new ArrayList<CourseTO>();
		}
	}
	
	class testCourseOperateSize1 extends CourseOperate{
		public ArrayList<CourseTO> getCourses(File file){
			ArrayList<CourseTO> toList = new ArrayList<CourseTO>();
			toList.add(new CourseTO());
			return toList;
		}
	}
	
	class testConfigTO extends ConfigTO{
		@Override
		public String getICSLocation(){
			return "";
		}
	}
	
	private ConfigTO to;
	private TimetableCreator tc;
	public TestTimeTableCreator(){
		to = new testConfigTO();
		to.setStoreName();
		to.setUniversity("cityu");
	}

	@Before
	public void setUp() throws Exception {
	}
	
	public void prepareCreator(ConfigTO to, ICSGenerator ics, CourseOperate co) throws Exception{
		Constructor[] cons = TimetableCreator.class.getDeclaredConstructors(); 
		cons[1].setAccessible(true); 
		tc = (TimetableCreator)cons[1].newInstance(to, ics, co);
	}

	//Test createTimeTable method 
	
	//Assume everything works fine
	@Test
	public void testTimetableCreator1() throws Exception{
		prepareCreator(to, new testICSTrue(), new testCourseOperateSize1());
		assertEquals(tc.createTimeTable(), true);
	}
	
	//Assume there is no course
	@Test
	public void testTimetableCreator2() throws Exception{
		prepareCreator(to, new testICSTrue(), new testCourseOperateSize0());
		assertEquals(tc.createTimeTable(), false);
	}
	
	//Assume course exists and testICS is false
	@Test
	public void testTimetableCreator3() throws Exception{
		prepareCreator(to, new testICSFalse(), new testCourseOperateSize0());
		assertEquals(tc.createTimeTable(), false);
	}

}
